import { create } from "zustand";
import { persist, createJSONStorage, devtools } from "zustand/middleware";

type State = {
  token: string;
  username: string;
};

type Action = {
  updateUser: (info: State) => void;
};

export const useUserStore = create<State & Action>()(
  devtools(
    persist(
      (set) => ({
        token: "",
        username: "",
        updateUser: (info: State) => set(() => ({ ...info })),
      }),
      {
        name: "user-storage",
      }
    )
  )
);
